package com.AdvancedDemos.LearnVariousAPI.字符串生成类;

public class StringBuilder拼接案例 {
    public static void main(String[] args) {
        System.out.println(getArrayData(new int[]{1, 2, 3, 4, 5}));
    }

    public static String getArrayData(int[] arr) {
        //1.判空
        if (arr == null) {
            return null;
        }
        //2.拼接
        StringBuilder sb = new StringBuilder();
        sb.append('[');
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                sb.append(arr[i]);
            } else {
                sb.append(arr[i]).append(", ");
            }
        }
        sb.append(']');
        return sb.toString();
    }

}
